package com.xu.quartz;

import com.xu.utils.RedisUtil;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.Set;

public class EndSelectJob implements Job {

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        redisUtil.set("select_state",2);
        System.out.println("选课已结束");
        try {
            Thread.sleep(1000*60*10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Set<String> keys = redisTemplate.keys("*");//清空redis数据库中所有的键值对
        redisTemplate.delete(keys);
        System.out.println("redis全部删除了");


    }
}
